#!/bin/bash

__write_remove(){
	cd "$INSTALLDIR"
	find | sort | while read line
	do
		if [ -f $line ] ; then
			echo "rm -f $line" | sed "s/\.\//\//g"
		fi
	done
	find | sort -r | while read line
	do
		if [ -d $line ] && [ $line != "." ] ; then
			echo "rmdir $line 2>/dev/null" | sed "s/\.\//\//g"
		fi
	done
	echo "rm -f /info/$name"
	echo "rm -f /info/$name.remove"
}

_create_metadata(){
	mkdir $PKGDIR/info/
	echo "----begin----" >> $PKGDIR/info/$name
	echo "Build date: $(date)" >> $PKGDIR/info/$name
	echo "Maintainer name: $maintainer" >> $PKGDIR/info/$name
	echo "Maintainer email: $email" >> $PKGDIR/info/$name
	echo "----info----" >> $PKGDIR/info/$name
	echo "Name: $name" >> $PKGDIR/info/$name
	echo "Version: $version" >> $PKGDIR/info/$name
	echo "Summary: $summary" >> $PKGDIR/info/$name
	echo "Description: $description" >> $PKGDIR/info/$name
	echo "----depends----" >> $PKGDIR/info/$name
	for dep in ${depends[@]}
	do
		echo "$dep" >> $PKGDIR/info/$name
	done
	echo "----files----" >> $PKGDIR/info/$name
	cd "$INSTALLDIR"
	find -type f | xargs md5sum >> $PKGDIR/info/$name
	echo "----end----" >> $PKGDIR/info/$name
	__write_remove >> $PKGDIR/info/$name.remove
}
_package(){
	cp -prfv "$INSTALLDIR"/* $PKGDIR/
	cd "$PKGDIR"
	tar -cf "$CURDIR"/$name-$version.tar *

}
